package com.laowang.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.WebUser;
import com.laowang.project.system.service.WebUserService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 网页端用户Controller
 * 
 * @author laowang
 * @date 2023-10-16
 */
@Api(tags = "网页端用户接口")
@RestController
@RequestMapping("/webUser")
public class WebUserController extends BaseController {
    @Autowired
    private WebUserService webUserService;

    @PostMapping("/register")
    public AjaxResult register(@Validated @RequestBody WebUser webUser) {
        webUserService.register(webUser);

        return AjaxResult.success("操作成功");
    }

    @PostMapping("/login")
    public AjaxResult login(@RequestBody WebUser webUser) {
        webUserService.login(webUser);

        return AjaxResult.success("操作成功");
    }


    /**
     * 查询网页端用户列表
     */
    @ApiOperation(value = "查询网页端用户列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebUser webUser) {
        startPage();
        List<WebUser> list = webUserService.selectWebUserList(webUser);
        return getDataTable(list);
    }
    
    /**
     * 导出网页端用户列表
     */
    @ApiOperation(value = "导出网页端用户列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:export')")
    @Log(title = "网页端用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WebUser webUser) {
        List<WebUser> list = webUserService.selectWebUserList(webUser);
        ExcelUtil<WebUser> util = new ExcelUtil<WebUser>(WebUser.class);
        return util.exportExcel(list, "webUser");
    }

    /**
     * 获取网页端用户详细信息
     */
    @ApiOperation(value = "获取网页端用户详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId) {
        return AjaxResult.success(webUserService.selectWebUserById(userId));
    }

    /**
     * 新增网页端用户
     */
    @ApiOperation(value = "新增网页端用户",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:add')")
    @Log(title = "网页端用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebUser webUser) {
        return toAjax(webUserService.insertWebUser(webUser));
    }

    /**
     * 修改网页端用户
     */
    @ApiOperation(value = "修改网页端用户",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:edit')")
    @Log(title = "网页端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebUser webUser) {
        return toAjax(webUserService.updateWebUser(webUser));
    }

    /**
     * 删除网页端用户
     */
    @ApiOperation(value = "删除网页端用户",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webUser:remove')")
    @Log(title = "网页端用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds) {
        return toAjax(webUserService.deleteWebUserByIds(userIds));
    }
}
